package com.study.hadoop.wordcount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Word Count Mapper实现类
 * 设置输入输出：/Users/stephen/Desktop/job.log /Users/stephen/Desktop/output
 * @author stephen
 * @date 2019-07-17 11:14
 */
public class WordcountMapper extends Mapper<LongWritable,Text, Text,LongWritable> {

    Text k = new Text();
    LongWritable v= new LongWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 1 获取一行
        String line = value.toString();
        // 2 切割
        String[] words = line.split(" ");
        // 3 输出
        for (String word : words) {
            k.set(word);
            context.write(k,v);
        }
    }
}
